import  { createRouter,createWebHistory,RouteRecordRaw } from "vue-router";
import { dynamic } from "./dynamic.ts"

const routes:Array<RouteRecordRaw> = [
    {
        path:'/login',
        name:'login',
        alias:['/'],
        meta:{
          type:'replace'
        },
        component:()=>import("../views/login/index.vue"?? "./")/* 懒路由加载 */
    },
    {
        path:'/home',
        name:'home',
        component:()=>import( "../views/home/index.vue" ?? "./"),
        children:[
            ...dynamic
        ]
    }
];

const router =  createRouter({
    history:createWebHistory(),
    routes
})

router.beforeEach( (to,from,next):void=>{
    //to  => 到那个页面去
    //from => 从哪个页面来
    //next => 回调函数
    console.log('前置路由守卫to:',to)
    console.log('前置路由守卫from:',from)
    console.log(routes)
    next(true)
} )

export default router


